package com.itrus.cvm;

import com.itrus.cert.X509CRL;
import com.itrus.util.LdapUtils;
import com.itrus.util.RegexUtils;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.cert.CRLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class CRLDownloadThread extends Thread
{
  private static Log log = LogFactory.getLog("ITRUS-CVM");
  private CRLContext m_CRLContext = null;

  public CRLDownloadThread(CRLContext paramCRLContext)
  {
    this.m_CRLContext = paramCRLContext;
  }

  private X509CRL downloadCRL()
  {
    String str1 = this.m_CRLContext.getCaAlias();
    String str2;
    String str3;
    if ((this.m_CRLContext.getCrlUrl() != null) && (this.m_CRLContext.getCrlUrl().startsWith("ldap://")))
    {
      str2 = this.m_CRLContext.getCrlUrl();
      str3 = "certificateRevocationList;binary";
      if (RegexUtils.matches(this.m_CRLContext.getCrlUrl(), "^ldap://.*/.*@.+"))
      {
        str3 = RegexUtils.exceptMatches(str2, "^ldap://.*/.*@");
        str2 = RegexUtils.exceptMatches(str2, "@" + str3);
      }
    }
    Object localObject;
    while (true)
    {
      try
      {
        X509CRL localX509CRL2 = X509CRL.getInstance(LdapUtils.getEntryBinaryAttr(str2, str3));
        localObject = localX509CRL2;
        if (localObject != null)
          break;
        return null;
      }
      catch (Exception localException3)
      {
        log.warn("(" + str1 + ")从[" + str2 + "]下载CRL时发生异常：" + localException3.getMessage());
        localObject = null;
        continue;
      }
      str2 = this.m_CRLContext.getCrlUrl();
      if (str2 != null)
        log.debug("(" + str1 + ")从指定的URL下载CRL。");
      try
      {
        while (true)
        {
          X509CRL localX509CRL1 = X509CRL.getInstanceFromURL(str2);
          localObject = localX509CRL1;
          break;
          str2 = this.m_CRLContext.getUserCrlUrl();
          log.debug("(" + str1 + ")从用户证书的URL地址。");
        }
      }
      catch (Exception localException1)
      {
        log.warn("(" + str1 + ")从[" + str2 + "]下载CRL时发生异常：" + localException1.getMessage());
        localObject = null;
      }
    }
    if ((!this.m_CRLContext.isNotCheckCRL()) && (!this.m_CRLContext.isCRLIssuedByLegalCA((X509CRL)localObject, this.m_CRLContext.getCaCert())))
    {
      log.warn("(" + str1 + ")从" + str2 + "下载到的CRL不是由指定的CA所颁发！");
      return null;
    }
    if (!((X509CRL)localObject).isOnValidPeriod())
    {
      log.warn("(" + str1 + ")从" + str2 + "下载到的CRL已过期！ThisUpdate:" + ((X509CRL)localObject).getThisUpdate() + ", NextUpdate:" + ((X509CRL)localObject).getNextUpdate());
      return null;
    }
    log.info("(" + str1 + ")从" + str2 + "下载到了有效的CRL文件！");
    try
    {
      saveCRLToFile((X509CRL)localObject, this.m_CRLContext.getCrlFilePath());
      log.info("(" + str1 + ")CRL文件写入成功！" + this.m_CRLContext.getCrlFilePath());
      return localObject;
    }
    catch (Exception localException2)
    {
      log.warn(localException2, localException2);
    }
    return localObject;
  }

  private X509CRL downloadCRLInPolicy()
  {
    String str = this.m_CRLContext.getCaAlias();
    this.m_CRLContext.setDownloading();
    int[] arrayOfInt = this.m_CRLContext.getRetryPolicy();
    int i = arrayOfInt.length;
    int j = 0;
    while (true)
    {
      if (j > i)
        return null;
      log.info("(" + str + ")一共尝试" + (i + 1) + "次，这是第" + (j + 1) + "次下载。");
      X509CRL localX509CRL = downloadCRL();
      if (localX509CRL != null)
      {
        log.info("(" + str + ")下载CRL成功。");
        this.m_CRLContext.setX509CRL(localX509CRL);
        this.m_CRLContext.setDownloaded();
        return localX509CRL;
      }
      if (j < i);
      try
      {
        log.info("(" + str + ")" + arrayOfInt[j] + "秒后会重新尝试下载。");
        Thread.sleep(1000 * arrayOfInt[j]);
        j++;
      }
      catch (InterruptedException localInterruptedException)
      {
        while (true)
          log.warn("(" + str + ")CRL重试更新线程被中断，间隔时间为" + arrayOfInt[j] + "秒。异常:" + localInterruptedException.getMessage());
      }
    }
  }

  private void saveCRLToFile(X509CRL paramX509CRL, String paramString)
    throws IOException, CRLException, InterruptedException
  {
    byte[] arrayOfByte = paramX509CRL.getEncoded();
    FileOutputStream localFileOutputStream = new FileOutputStream(paramString);
    localFileOutputStream.write(arrayOfByte);
    localFileOutputStream.close();
  }

  // ERROR //
  public void run()
  {
    // Byte code:
    //   0: iconst_1
    //   1: aload_0
    //   2: getfield 26	com/itrus/cvm/CRLDownloadThread:m_CRLContext	Lcom/itrus/cvm/CRLContext;
    //   5: invokevirtual 234	com/itrus/cvm/CRLContext:getStatus	()I
    //   8: if_icmpne +4 -> 12
    //   11: return
    //   12: aload_0
    //   13: getfield 26	com/itrus/cvm/CRLDownloadThread:m_CRLContext	Lcom/itrus/cvm/CRLContext;
    //   16: invokevirtual 36	com/itrus/cvm/CRLContext:getCaAlias	()Ljava/lang/String;
    //   19: astore_1
    //   20: aload_0
    //   21: getfield 26	com/itrus/cvm/CRLDownloadThread:m_CRLContext	Lcom/itrus/cvm/CRLContext;
    //   24: invokevirtual 237	com/itrus/cvm/CRLContext:isTimingDownload	()Z
    //   27: ifne +47 -> 74
    //   30: aload_0
    //   31: invokespecial 239	com/itrus/cvm/CRLDownloadThread:downloadCRLInPolicy	()Lcom/itrus/cert/X509CRL;
    //   34: ifnonnull +32 -> 66
    //   37: getstatic 20	com/itrus/cvm/CRLDownloadThread:log	Lorg/apache/commons/logging/Log;
    //   40: new 65	java/lang/StringBuilder
    //   43: dup
    //   44: ldc 91
    //   46: invokespecial 70	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   49: aload_1
    //   50: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   53: ldc 241
    //   55: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   58: invokevirtual 77	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   61: invokeinterface 104 2 0
    //   66: aload_0
    //   67: getfield 26	com/itrus/cvm/CRLDownloadThread:m_CRLContext	Lcom/itrus/cvm/CRLContext;
    //   70: invokevirtual 198	com/itrus/cvm/CRLContext:setDownloaded	()V
    //   73: return
    //   74: aload_0
    //   75: invokespecial 239	com/itrus/cvm/CRLDownloadThread:downloadCRLInPolicy	()Lcom/itrus/cert/X509CRL;
    //   78: astore_3
    //   79: aload_3
    //   80: ifnull +84 -> 164
    //   83: new 243	java/util/Date
    //   86: dup
    //   87: invokespecial 244	java/util/Date:<init>	()V
    //   90: astore 4
    //   92: aload_3
    //   93: invokevirtual 151	com/itrus/cert/X509CRL:getNextUpdate	()Ljava/util/Date;
    //   96: invokevirtual 248	java/util/Date:getTime	()J
    //   99: lstore 5
    //   101: aload 4
    //   103: invokevirtual 248	java/util/Date:getTime	()J
    //   106: lstore 7
    //   108: lload 5
    //   110: lload 7
    //   112: lsub
    //   113: lstore 9
    //   115: getstatic 20	com/itrus/cvm/CRLDownloadThread:log	Lorg/apache/commons/logging/Log;
    //   118: new 65	java/lang/StringBuilder
    //   121: dup
    //   122: ldc 91
    //   124: invokespecial 70	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   127: aload_1
    //   128: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   131: ldc 250
    //   133: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   136: aload_3
    //   137: invokevirtual 151	com/itrus/cert/X509CRL:getNextUpdate	()Ljava/util/Date;
    //   140: invokevirtual 251	java/util/Date:toString	()Ljava/lang/String;
    //   143: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   146: ldc 253
    //   148: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   151: invokevirtual 77	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   154: invokeinterface 156 2 0
    //   159: lload 9
    //   161: invokestatic 206	java/lang/Thread:sleep	(J)V
    //   164: getstatic 20	com/itrus/cvm/CRLDownloadThread:log	Lorg/apache/commons/logging/Log;
    //   167: ldc 255
    //   169: invokeinterface 109 2 0
    //   174: goto -154 -> 20
    //   177: astore_2
    //   178: aload_0
    //   179: getfield 26	com/itrus/cvm/CRLDownloadThread:m_CRLContext	Lcom/itrus/cvm/CRLContext;
    //   182: invokevirtual 198	com/itrus/cvm/CRLContext:setDownloaded	()V
    //   185: aload_2
    //   186: athrow
    //   187: astore 11
    //   189: getstatic 20	com/itrus/cvm/CRLDownloadThread:log	Lorg/apache/commons/logging/Log;
    //   192: new 65	java/lang/StringBuilder
    //   195: dup
    //   196: ldc 91
    //   198: invokespecial 70	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   201: aload_1
    //   202: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   205: ldc_w 257
    //   208: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   211: lload 9
    //   213: ldc2_w 258
    //   216: ldiv
    //   217: invokevirtual 262	java/lang/StringBuilder:append	(J)Ljava/lang/StringBuilder;
    //   220: ldc 210
    //   222: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   225: aload 11
    //   227: invokevirtual 211	java/lang/InterruptedException:getMessage	()Ljava/lang/String;
    //   230: invokevirtual 74	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   233: invokevirtual 77	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   236: invokeinterface 265 2 0
    //   241: goto -77 -> 164
    //
    // Exception table:
    //   from	to	target	type
    //   20	66	177	finally
    //   74	79	177	finally
    //   83	108	177	finally
    //   115	164	177	finally
    //   164	174	177	finally
    //   189	241	177	finally
    //   115	164	187	java/lang/InterruptedException
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cvm.CRLDownloadThread
 * JD-Core Version:    0.6.2
 */